package com.nf.health.app.healthbank.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.adapter.OnMyClickListener;
import com.nf.health.app.adapter.ViewHolder;
import com.nf.health.app.healthbank.bean.HealthBankVo;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/6/23
 * 健康银行适配器
 * .
 */
public class MyHealthyBankAdapter extends BaseAdapter {
    List<HealthBankVo> newsList;
    Activity activity;
    LayoutInflater inflater = null;


    public MyHealthyBankAdapter(Activity activity, List<HealthBankVo> newsList) {
        this.activity = activity;
        this.newsList = newsList;
        inflater = LayoutInflater.from(activity);
    }

    @Override
    public int getCount() {
        return newsList == null ? 0 : newsList.size();
    }

    @Override
    public Object getItem(int position) {
        if (newsList != null && newsList.size() != 0) {
            return newsList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        HealthBankVo item = newsList.get(position);
        ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_healthy_bank, position);
        ImageView iv_img = holder.getView(R.id.my_healthy_image);
        TextView btn_foucus_bank = holder.getView(R.id.btn_foucus_bank);
        ImageLoaderUtils.getinstance(activity).getImage(iv_img, item.getHimg(), R.drawable.default_image);
        holder.setText(R.id.my_healthy_name, item.getNick());
        if(!TextUtils.isEmpty(item.getFdept())){
            holder.setText(R.id.tv_fdept, item.getFdept());
        }else{
           holder.getView(R.id.tv_fdept).setVisibility(View.GONE);
        }

        if ("y".equals(item.getIsfollow())) {
            btn_foucus_bank.setText("取消关注");
            btn_foucus_bank.setTextColor(Color.GRAY);
        } else {
            btn_foucus_bank.setText("  关注  ");
            btn_foucus_bank.setTextColor(activity.getResources().getColor(R.color.theme_color));
        }

        btn_foucus_bank.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null)
                    listener.onClick(position, "");
            }
        });

        return holder.getConvertView();
    }


    private OnMyClickListener listener;

    public void setOnMyClickListener(OnMyClickListener listener) {
        this.listener = listener;
    }
}